<template>
	<view class="index-container">
		<view class="swiper">
			<u-swiper :list="imgs" height="300rpx" indicator indicatorMode="dot" circular />
		</view>
		<view class="content">
			<view class="title">
				<text>任务中心</text>
			</view>
			<view class="collapse">
				<u-collapse accordion>
					<u-collapse-item v-for="item in taskList" :key="item.id" :title="item.title" :name="item.id">
						<u-cell v-for="it in item.paperItems">
							<text slot="title">{{it.examPaperName}}</text>
							<view class="cell-value" slot="value">
								<view class="cell-value-view" v-if="it.status==1">
									<u-tag text="待批改" type="warning" plain plainFill></u-tag>
									<text class="value-text">批改试卷</text>
								</view>
								<view class="cell-value-view" v-if="it.status==2">
									<u-tag text="成功" type="success" plain plainFill></u-tag>
									<text class="value-text">查看试卷</text>
								</view>
								<text v-else-if="it.status==null" @tap="startPaper" :data-id="it.examPaperId"
									class="value-text">开始答题</text>
							</view>
						</u-cell>
					</u-collapse-item>
				</u-collapse>
			</view>
			<view class="title">
				<text>固定试卷</text>
			</view>
			<view class="cell">
				<u-cell v-for="item in fixedPaper" :key="item.id" :title="item.name" isLink></u-cell>
			</view>
			<view class="title">
				<text>时段试卷</text>
			</view>
			<view class="cell">
				<u-cell v-for="item in timeLimitPaper" :key="item.id" :title="item.name" isLink></u-cell>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '../../http.js'
	export default {
		data() {
			return {
				imgs: [
					"https://tse3-mm.cn.bing.net/th/id/OIP-C.6glxjeieIeEBBAOWQnZcIgHaEJ?w=310&h=180&c=7&r=0&o=7&dpr=1.3&pid=1.7&rm=3",
					"https://tse2-mm.cn.bing.net/th/id/OIP-C.1lEIKFtGBxlZQ5CvNN02NwHaEJ?w=327&h=183&c=7&r=0&o=7&dpr=1.3&pid=1.7&rm=3",
					"https://tse3-mm.cn.bing.net/th/id/OIP-C.6glxjeieIeEBBAOWQnZcIgHaEJ?w=310&h=180&c=7&r=0&o=7&dpr=1.3&pid=1.7&rm=3",
					"https://tse2-mm.cn.bing.net/th/id/OIP-C.1lEIKFtGBxlZQ5CvNN02NwHaEJ?w=327&h=183&c=7&r=0&o=7&dpr=1.3&pid=1.7&rm=3"
				],
				taskList: [],
				fixedPaper: [],
				timeLimitPaper: []
			}
		},
		onLoad() {
			this.getTask()
			this.getList()
		},
		onShow() {
			this.getTask()
			this.getList()
		},
		methods: {
			getTask() {
				http({
					url: '/api/student/dashboard/task',
					method: 'POST'
				}).then(res => {
					console.log(res);
					if (res.code === 1) {
						this.taskList = res.response
					}
				})
			},
			getList() {
				http({
					url: '/api/student/dashboard/index',
					method: 'POST'
				}).then(res => {
					console.log(res);
					if (res.code === 1) {
						this.fixedPaper = res.response.fixedPaper
						this.timeLimitPaper = res.response.timeLimitPaper
					}
				})
			},
			startPaper(e) {
				console.log(e.target.dataset.id);
				uni.navigateTo({
					url: '/pages/paper/paper?id=' + e.target.dataset.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.index-container {
		.title {
			height: 80rpx;
			background-color: #F7F7F7;
			padding-left: 30rpx;
			display: flex;
			align-items: center;
		}

		.collapse {

			.value-text {
				color: #409EFF;
				margin-left: 20rpx;
			}

			.cell-value-view {
				display: flex;
				justify-content: space-around;
				align-items: center;
			}
		}
	}
</style>